<template>
  <div class="newsList">
    <div class="cart" v-for="item in newsList" :key="item.id" @click="newsDetail(item.id)">
      <div class="left">
        <img :src="item.img_url" alt />
      </div>
      <div class="right">
        <p>{{ item.title }}</p>
        <p>
          <span>
            发表时间: {{ item.add_time | dataTime }}
            <span>点击: {{ item.click }} 次</span>
          </span>
        </p>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "newsList",
  data() {
    return {
        newsList: [
            { add_time: "1563858964", click: 1, id: 0, img_url: "https://ss0.baidu.com/73x1bjeh1BF3odCf/it/u=952337662,615710730&fm=85", title: "一想二干三成功，企业是船。", abstract: "摘要1" },
            { add_time: "1563859201", click: 3, id: 1, img_url: "https://ss3.baidu.com/-rVXeDTa2gU2pMbgoY3K/it/u=3351050582,3466620827&fm=202&mola=new&crop=v1", title: "一丝之差，优劣分家。", abstract: "摘要2" },
            { add_time: "1562094246", click: 5, id: 2, img_url: "https://ss0.baidu.com/73t1bjeh1BF3odCf/it/u=4249430510,135948101&fm=85", title: "您的自觉贡献，才有公司的辉煌。", abstract: "摘要3" },
        ]
    }
  },
  created() {
    // this.getNewsList()
  },
  methods: {
    getNewsList() {// 获取列表数据
      this.$axios.get("http://suggest.taobao.com").then(response => {
          // 请求成功
        }).catch(error => {
          // 请求失败
        });
    },
    newsDetail(id) {
        this.$router.push({
            path: '/newsDetail',
            query: {
                id: id
            }
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.newsList {
  .cart {
    padding: 0 10px 0 10px;
    &:active {
      background: #d9d9d9;
      img {
        opacity: 0.3;
      }
    }
    display: flex;
    border-bottom: 1px solid #d9d9d9;
    .left {
      display: flex;
      flex-direction: column;
      justify-content: center;
      img {
        width: 60px;
        height: 60px;
        padding: 5px;
      }
    }
    .right {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      flex: 1;
      padding: 5px 10px 5px 10px;
      p {
        font-size: 16px;
        padding: 4px 0;
      }
      p span {
        display: flex;
        justify-content: space-between;
        font-size: 13px;
        color: #00BFFF;
      }
    }
  }
}
</style>